class Solution:
    def minimumLength(self, s: str) -> int:
        left = 0
        right = len(s) - 1
        length = len(s)
        while left < right:
            if s[left] != s[right]:
                break
            ld = 1
            rd = 1
            while left + 1 < right and s[left] == s[left + 1]:
                left += 1
                ld += 1
            while right - 1 > left and s[right] == s[right - 1]:
                right -= 1
                rd += 1
            if left == right:
                length -= 1
            else:
                length -= (ld + rd)
            left += 1
            right -= 1

        return length
